<template>
  <div>
    <!-- <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/adminedit">岛主信息</a></el-breadcrumb-item>
    </el-breadcrumb> -->
    <el-card>
      <el-form ref="form" :model="info" :rules="rules" label-width="80px">
        <el-form-item label="名称:" prop="nickname">
          <el-input v-model="info.nickname"></el-input>
        </el-form-item>
        <el-form-item label="老密码:" prop="password">
          <el-input v-model="info.password" type="password" show-password></el-input>
        </el-form-item>
        <el-form-item label=" 新密码:" prop="repassword">
          <el-input v-model="info.repassword" type="password" show-password></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">修改</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { editAdminApi } from '../../request/apis'
export default {
  data () {
    const checkPassword = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        if (this.info.password !== '') {
          this.$refs.form.validateField('repassword')
        }
        callback()
      }
    }
    const recheckPassword = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.info.password) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      info: {
        nickname: '',
        password: '',
        repassword: ''
      },
      rules: {
        nickname: [{ required: true, message: '请输入名称', trigger: 'blur' }],
        password: [
          { validator: checkPassword, trigger: 'blur' }
        ],
        repassword: [
          { validator: recheckPassword, trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.info.nickname = window.sessionStorage.getItem('nickname')
  },
  methods: {
    onSubmit () {
      console.log('submit!')
      this.editAdmin()
    },
    editAdmin () {
      editAdminApi(this.info).then((res) => {
      })
    }
  }
}
</script>

<style scoped>
</style>
